package Demo26;

import java.util.Scanner;

/**
 *  【模板】二维前缀和
 *  https://www.nowcoder.com/practice/99eb8040d116414ea3296467ce81cbbc?tpId=230&tqId=2023819&ru=/exam/oj&qru=/ta/dynamic-programming/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196
 *  两步
 *  1. 预处理前缀和矩阵
 *  2. 使用前缀和矩阵
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();
        int[][] arr = new int[n + 1][m + 1];
        long[][] dp = new long[n + 1][m + 1];
        // 读取值
        for (int x = 1; x <= n; x++) {
            for (int y = 1; y <= m; y++) {
                arr[x][y] = in.nextInt();
            }
        }
        // 处理前缀和矩阵
        for (int x = 1; x <= n; x++) {
            for (int y = 1; y <= m; y++) {
                dp[x][y] = dp[x - 1][y] + dp[x][y-1] - dp[x - 1][y - 1] + arr[x][y];
            }
        }
        // 使用前缀和矩阵
        while(q > 0) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            System.out.println(dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1]);
            q--;
        }
    }
}